package lion.common;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class ArrayUtility {

	@SafeVarargs
	public static <T> List<T> asList(T... a) {
		List<T> retList = new ArrayList<T>(a.length);
		for (T aT : a) {
			retList.add(aT);
		}
		return retList;
	}

	public static int[] toArray(List<Integer> param) {
		int[] ret = new int[param.size()];
		for (int i = 0; i < param.size(); i++) {
			ret[i] = param.get(i);
		}
		return ret;
	}

	public static short[] toShortArray(List<Short> param) {
		short[] ret = new short[param.size()];
		for (int i = 0; i < param.size(); i++) {
			ret[i] = param.get(i);
		}
		return ret;
	}

	public static byte[] toByteArray(List<Byte> param) {
		byte[] ret = new byte[param.size()];
		for (int i = 0; i < param.size(); i++) {
			ret[i] = param.get(i);
		}
		return ret;
	}

	public static void fill(byte[][] a, byte val) {
		for (int i = 0, len = a.length; i < len; i++)
			for (int j = 0; j < a[i].length; j++)
				a[i][j] = val;
	}

	public static void fill(int[][] a, int val) {
		for (int i = 0, len = a.length; i < len; i++)
			for (int j = 0; j < a[i].length; j++)
				a[i][j] = val;
	}
    public static void fill(boolean[] a,boolean val) {
    	for(int i = 0, len = a.length; i < len; i++) {
    		a[i] = val;
    	}
    }
	public static void fill(byte[][][] a, byte val) {
		for (int i = 0, len = a.length; i < len; i++)
			for (int j = 0; j < a[i].length; j++)
				for (int k = 0; k < a[i][j].length; k++)
					a[i][j][k] = val;
	}
    public static int[] short2Int(short [] socre) {
    	int[] retlist = new int[socre.length];
		for (int i = 0; i < socre.length; i++) {
			retlist[i] = (int) (socre[i]);
		}
		return retlist;
    }
	public static int[] long2Int(long[] m_lGameScore) {
		int[] retlist = new int[m_lGameScore.length];
		for (int i = 0; i < m_lGameScore.length; i++) {
			retlist[i] = (int) (m_lGameScore[i]);
		}
		return retlist;
	}

	public static short[] int2Short(int[] m_lGameScore) {
		short[] retlist = new short[m_lGameScore.length];
		for (int i = 0; i < m_lGameScore.length; i++) {
			retlist[i] = (short) (m_lGameScore[i]);
		}
		return retlist;
	}
	
	public static byte[] toByteArray(Set<Integer> connectedPlayerSet) {
		byte[] ret = new byte[connectedPlayerSet.size()];
		int i = 0;
		for (int aInt : connectedPlayerSet) {
			ret[i++] = (byte) aInt;
		}
		return ret;
	}

}
